//
//  HYBJsObjCModel.m
//  JavaScriptAndObjectiveC
//
//  Created by 刘红武 on 2018/4/27.
//  Copyright © 2018年 huangyibiao. All rights reserved.
//

#import "HWJsObjCModel.h"
#import "KBRouter.h"
@implementation HWJsObjCModel

- (void)callWithDict:(NSDictionary *)params {
    //功能分发 开始路由器
    [[KBRouter shard] issueAction:params Controller:nil WebView:self.webView jsContect:self.jsContext];
    
}

// Js调用了callSystemCamera
- (void)callSystemCamera {
    NSLog(@"JS调用了OC的方法，调起系统相册");
    
    // JS调用后OC后，又通过OC调用JS，但是这个是没有传参数的
    JSValue *jsFunc = self.jsContext[@"jsFunc"];
    [jsFunc callWithArguments:nil];  // Arguments 为JS的参数
}

- (void)jsCallObjcAndObjcCallJsWithDict:(NSDictionary *)params {
    NSLog(@"jsCallObjcAndObjcCallJsWithDict was called, params is %@", params);
    
    // 调用JS的方法
    JSValue *jsParamFunc = self.jsContext[@"jsParamFunc"];
    [jsParamFunc callWithArguments:@[@{@"age": @10, @"name": @"lili", @"height": @158}]];
}

- (void)showAlert:(NSString *)title msg:(NSString *)msg {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertView *a = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [a show];
    });
}

@end
